import { ViewStyle, TextStyle, ImageStyle } from 'react-native';
import { Theme } from './theme';

type Style = ViewStyle | TextStyle | ImageStyle;

export function createThemedStyle<T extends Style>(
  styleFactory: (theme: Theme) => T
): (theme: Theme) => T {
  return styleFactory;
}

export function mergeStyles<T extends Style>(
  ...styles: (T | undefined | null | false)[]
): T {
  return Object.assign({}, ...styles.filter(Boolean)) as T;
}

export function getShadowStyle(
  theme: Theme, 
  size: keyof typeof theme.shadows
): ViewStyle {
  return theme.shadows[size];
}

export function getTypographyStyle(
  theme: Theme,
  size: keyof typeof theme.typography.sizes,
  weight: keyof typeof theme.typography.weights = 'regular'
): TextStyle {
  return {
    fontSize: theme.typography.sizes[size],
    fontWeight: theme.typography.weights[weight],
  };
} 